package com.canyou.service;

import cn.hutool.core.exceptions.ExceptionUtil;
import com.canyou.utils.JsonUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;

/**
 * 日志处理类
 *
 * @author: cgz
 * @date: 2019/6/16
 */
@Service
public interface RequestLogService {

    Logger log = LoggerFactory.getLogger(RequestLogService.class);

    /**
     * 记录请求日志
     *
     * @param module
     * @param operation
     * @param arg
     * @param result
     * @param e
     * @param request
     * @param times
     * @param userName
     * @param clientId
     */
    default void insert(String module, String operation, String arg, Object result, Exception e,
                        HttpServletRequest request, Long times, String userName, String clientId) {
        log.debug("请求日志：\n模块：{}\n操作：{}\n参数：{}\n结果：{}\n异常：{}\n请求耗时：{}ms\n操作人：{}\n客户端：{}",
                module, operation, arg, JsonUtils.toString(result), ExceptionUtil.stacktraceToString(e),
                times, userName, clientId);
    }
}
